local skel = fk.CreateSkill{
  name = "tea__zhengyin",
  tags = { Skill.Switch }
}
local U = require "packages/utility/utility"
Fk:loadTranslationTable{
  ["tea__zhengyin"] = "正音",
  [":tea__zhengyin"] = "转换技，每轮每种牌名限一次，①你可以将至少X张红色牌当做任意一张基本牌或普通锦囊牌使用；②你可以展示X张黑" ..
  "色牌并将之置于牌堆顶，视为使用任意一张基本牌或普通锦囊牌（X为本轮此技能的发动次数）。",
  ["#tea__zhengyin-yang"] = "正音：①你可以将至少 %arg 张红色牌当任意基本牌或普通锦囊牌使用",
  ["#tea__zhengyin-yin"] = "正音：①你可以展示至少 %arg 张黑色牌并将之置于牌堆顶， 视为使用任意基本牌或普通锦囊牌",
}
---@type ViewAsSkillSpec
local zhengyin = {
  mute = true,
  pattern = ".|.|.|.|.|basic,trick",
  prompt = function (self, player, selected_cards, selected)
    local num = player:usedSkillTimes(skel.name, Player.HistoryRound) + 1
    if player:getSwitchSkillState(skel.name) == fk.SwitchYang then
      return "#tea__zhengyin-yang:::" .. tostring(num)
    else
      return "#tea__zhengyin-yin:::" .. tostring(num)
    end
  end,
  interaction = function (self, player)
    local all_names = Fk:getAllCardNames("bt", false)
    local subcards
    if player:getSwitchSkillState(skel.name) == fk.SwitchYang then
      subcards = player:getCardIds("he")
    end
    local names = player:getViewAsCardNames(skel.name, all_names, subcards, player:getTableMark(skel.name .. "-round"))
    return UI.CardNameBox{ choices = names, all_choices = all_names }
  end,
  card_filter = function (self, player, to_select, selected)
    if player:getSwitchSkillState(skel.name) == fk.SwitchYang then
      return Fk:getCardById(to_select).color == Card.Red
    else
      return Fk:getCardById(to_select).color == Card.Black
    end
  end,
  view_as = function (self, player, cards)
    local num = player:usedSkillTimes(skel.name, Player.HistoryRound) + 1
    if #cards < num or not self.interaction.data then return end
    local c = Fk:cloneCard(self.interaction.data)
    c:addSubcards(cards)
    c.skillName = skel.name
    return c
  end,
  before_use = function (self, player, use)
    local room = player.room
    room:notifySkillInvoked(player, skel.name, "switch")
    local index = player:getSwitchSkillState(skel.name, true) == fk.SwitchYang and 1 or 2
    player:broadcastSkillInvoke(skel.name, index)
    local name = use.card.trueName
    local mark = player:getTableMark(skel.name .. "-round")
    table.insertIfNeed(mark, name)
    room:setPlayerMark(player, skel.name .. "-round", mark)
    if player:getSwitchSkillState(skel.name, true) == fk.SwitchYin then
      local cids = table.simpleClone(use.card.subcards)
      use.card:clearSubcards()
      player:showCards(cids)
      room:moveCardTo(cids, Card.DrawPile, nil, fk.ReasonPut, skel.name, nil, true, player)
    end
  end,
  enabled_at_response = function (self, player, response)
    if Fk.currentResponsePattern =="nullification" and table.contains(player:getTableMark(skel.name .. "-round"), "nullification") then return false end  --取消无懈烧条
    return not response
  end
}
skel:addEffect("viewas", zhengyin)
return skel